package com.richapp.launcher.receiver;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Gravity;
import android.widget.Toast;

import com.richapp.launcher.ui.fragments.home.Title_Fragment;
import com.tencent.android.tpush.XGPushBaseReceiver;
import com.tencent.android.tpush.XGPushClickedResult;
import com.tencent.android.tpush.XGPushRegisterResult;
import com.tencent.android.tpush.XGPushShowedResult;
import com.tencent.android.tpush.XGPushTextMessage;

/**
 * Created by jack on 2015/5/11 0011.
 */
public class XingeMessageReceiver extends XGPushBaseReceiver{

    private static final String TAG = XingeMessageReceiver.class.getName();

    @Override
    public void onRegisterResult(Context context, int i, XGPushRegisterResult xgPushRegisterResult) {
        Log.d(TAG, "注册结果:" + i);
        String token = xgPushRegisterResult.getToken();
        Log.d(TAG, "注册的token:" + token);
    }

    @Override
    public void onUnregisterResult(Context context, int i) {
        Log.d(TAG,"反注册结果:"+i);
    }

    @Override
    public void onSetTagResult(Context context, int i, String s) {
        Log.d(TAG,"设置标签:"+s);
    }

    @Override
    public void onDeleteTagResult(Context context, int i, String s) {
        Log.d(TAG, "删除标签结果:" + i+" 标签:"+s);
    }

    @Override
    public void onTextMessage(Context context, XGPushTextMessage message) {
        if(context == null || message == null){
            return;
        }
        Intent intent = new Intent();
        intent.setAction(Title_Fragment.ACTION_USER_MESSAGE_RECEIVE);
        intent.putExtra("message", message.getContent());
        context.sendBroadcast(intent);

        Toast toast = Toast.makeText(context, message.getContent(), Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    @Override
    public void onNotifactionClickedResult(Context context, XGPushClickedResult xgPushClickedResult) {
        Log.d(TAG, "用户点击了通知:"+xgPushClickedResult.getContent());
    }

    @Override
    public void onNotifactionShowedResult(Context context, XGPushShowedResult result) {
        if(context == null || result == null){
            return;
        }

        Intent intent = new Intent();
        intent.setAction(Title_Fragment.ACTION_USER_MESSAGE_RECEIVE);
        intent.putExtra("message", result.getContent());
        context.sendBroadcast(intent);

        Toast toast = Toast.makeText(context, result.getContent(), Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }
}
